// pages/drawingTool/drawingTool.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
      url:"https://s.ruidcn.cn/drawingToolPageView?addr=23&path=全盟电力展示大厅/展示大厅.json.json&token=14f16e73-d3fe-4cc0-a815-a15f708790f0&websocket=rabt",
      url2:"https://www.liuyankun.xyz/view?addr=7&path=厂区配电室/7-3.json&token=9ba3bf7d-1f84-4696-81bb-e6a257fa08c4&websocket=rabt",
      url1:"http://192.168.0.127:8000/mobileView?addr=7&path=厂区配电室/7-3.json&token=9ba3bf7d-1f84-4696-81bb-e6a257fa08c4&websocket=rabt",
      url3:`http://36.7.159.30:8089/view?addr=23&path=全盟电力展示大厅/展示大厅.json&token=14f16e73-d3fe-4cc0-a815-a15f708790f0&websocket=rabt`,
      data:{
        path: "厂区配电室/7-3.json",
        addr: 7,
        token: "9ba3bf7d-1f84-4696-81bb-e6a257fa08c4",
        websoket: "rabt"
      },
      // 初始缩放比例
      scale: 1,
      // 记录双指起始距离
      startDistance: 0,
      // 记录上一次的缩放比例
      lastScale: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({ url3:`http://36.7.159.30:8089/view?addr=23&path=${encodeURIComponent('全盟电力展示大厅/展示大厅')}.json&token=14f16e73-d3fe-4cc0-a815-a15f708790f0&websocket=rabt`})
      console.log(this.data.url)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  toAllHandle(e){ 
    var { key } = e.detail 
      this.setData({
        eqIndex: 1, 
        isShowPop: false
      })
      var { type } = $.detail(e)
      Store.dispatch({
        type: 'SET_FROM',
        form: {
          key: 'selected', // 后台要的更改字段 
          type: 3, // 表单类型 1： radio  2：select 3:特殊的radio
          config: {

          },
        },
      })
      $.linkurl(`/pages/main/chooseForm/chooseForm`)
        
  },
  childPageOnLoad(e){
    var data={
      path: "厂区配电室/7-3.json",
      addr: 7,
      token: "9ba3bf7d-1f84-4696-81bb-e6a257fa08c4",
      websoket: "rabt"
    };
    console.log(data)
    // wx.miniProgram.postMessage({"data":data})
  },
  onTouchStart(event) {
    console.log(event)
    // 判断是否为双指触摸
    if (event.touches.length === 2) {
      const touch1 = event.touches[0];
      const touch2 = event.touches[1];
      // 计算双指起始距离
      this.data.startDistance = this.getDistance(touch1, touch2);
    }
  },
  onTouchMove(event) {
    if (event.touches.length === 2) {
      const touch1 = event.touches[0];
      const touch2 = event.touches[1];
      const currentDistance = this.getDistance(touch1, touch2);
      const deltaScale = currentDistance / this.data.startDistance;
      // 计算新的缩放比例
      const newScale = this.data.lastScale * deltaScale;
      this.setData({
        scale: newScale
      });
    }
  },
  onTouchEnd() {
    // 记录上一次的缩放比例
    this.data.lastScale = this.data.scale;
  },
  // 计算两点之间的距离
  getDistance(touch1, touch2) {
    const dx = touch1.clientX - touch2.clientX;
    const dy = touch1.clientY - touch2.clientY;
    return Math.sqrt(dx * dx + dy * dy);
  }

})